| Conditions | 1 |
| Paths | 2 |
| Total Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* global API */ |
||
| 36 | .controller('MainCtrl', ['$scope', '$mdSidenav', '$rootScope', function ($scope, $mdSidenav, $rootScope) { |
||
| 37 | function buildToggler(navID) { |
||
| 38 | return function() { |
||
| 39 | // Component lookup should always be available since we are not using `ng-if` |
||
| 40 | $mdSidenav(navID) |
||
| 41 | .toggle(); |
||
| 42 | }; |
||
| 43 | } |
||
| 44 | |||
| 45 | $scope.toolbarShown = true; |
||
| 46 | |||
| 47 | $rootScope.$on('lockExtension', function () { |
||
| 48 | $scope.lockExtension(); |
||
| 49 | }); |
||
| 50 | |||
| 51 | $rootScope.$on('unlocked', function () { |
||
| 52 | $scope.toolbarShown = true; |
||
| 53 | }); |
||
| 54 | |||
| 55 | $scope.toggleLeft = buildToggler('left'); |
||
| 56 | |||
| 57 | $scope.lockExtension = function () { |
||
| 58 | $scope.toolbarShown = false; |
||
| 59 | API.runtime.sendMessage(API.runtime.id, {method: "setMasterPassword", args: {password: null}}).then(function () { |
||
| 60 | window.location = '#!/locked'; |
||
| 61 | }); |
||
| 62 | }; |
||
| 63 | |||
| 64 | $scope.goto_list = function () { |
||
| 65 | window.location = '#!/'; |
||
| 66 | $mdSidenav('left').close(); |
||
| 67 | }; |
||
| 68 | $scope.goto_settings = function () { |
||
| 69 | window.location = '#!/settings'; |
||
| 70 | $mdSidenav('left').close(); |
||
| 71 | }; |
||
| 72 | |||
| 73 | $scope.goto_search = function () { |
||
| 74 | window.location = '#!/search'; |
||
| 75 | $mdSidenav('left').close(); |
||
| 76 | }; |
||
| 77 | |||
| 78 | API.runtime.sendMessage(API.runtime.id, {'method': 'getRuntimeSettings'}).then(function (settings) { |
||
| 79 | $rootScope.app_settings = settings; |
||
| 80 | if (!settings || Object.keys(settings).length === 0) { |
||
| 81 | window.location = '#!/setup'; |
||
| 82 | } else if (settings.hasOwnProperty('isInstalled')) { |
||
| 83 | $scope.lockExtension(); |
||
| 84 | } |
||
| 85 | }); |
||
| 86 | |||
| 87 | }]); |
||
| 88 | }()); |
||
| 90 |